<cpanel setvar="headerimg=../images/mailmenu.gif">
<cpanel setvar="dprefix=../">
<cpanel Branding="include(stdheader.html)">
<script type="text/javascript">
//<![CDATA[

<cpanelif $appname==webmail>
var init_page = function() {
	var forward_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('Forward Address')">");
	forward_validator.add("fwdemail", "email", "<cpanel langprint="email_not_valid_email">");
	forward_validator.attach();
	
	CPANEL.validate.attach_to_form("submit", forward_validator);
	
	YAHOO.util.Dom.get("fwdemail").focus();
};
YAHOO.util.Event.onDOMReady(init_page);
</cpanelif>

<cpanelif !$appname==webmail>
var toggle_radios = function() {
	if (YAHOO.util.Dom.get("fwd_radio").checked == true) {
		discard_validator.clear_messages();
		dir_validator.clear_messages();
	}
	else if (YAHOO.util.Dom.get("discard_radio").checked == true) {
		fwd_validator.clear_messages();
		dir_validator.clear_messages();
	}
	else if (YAHOO.util.Dom.get("pipeit").checked == true) {
		fwd_validator.clear_messages();
		discard_validator.clear_messages();
	}
	else if (YAHOO.util.Dom.get("fwdopt_blackhole").checked == true) {
		fwd_validator.clear_messages();
		discard_validator.clear_messages();
		dir_validator.clear_messages();
	}
    else if (YAHOO.util.Dom.get("fwdsystem_radio").checked == true) {
		fwd_validator.clear_messages();
		discard_validator.clear_messages();
        dir_validator.clear_messages();
    }
};

//a bit more complicated than other validators because the criteria
//can be altered in WHM
var validate_system_user = function() {
    var value = YAHOO.util.Dom.get("fwdsystem").value;

    return CPANEL.validate.alphanumeric( value )
        && CPANEL.validate.no_chars( value, ' ' )
    ;
}

var validate_destination = function() {
	if (YAHOO.util.Dom.get("fwd_radio").checked) {
        var email_list = YAHOO.util.Dom.get("fwdemail").value.trim();
        var emails = email_list.split(/\s*,\s*/);
        return emails.every(CPANEL.validate.email);
	}
	else return true;
};

var validate_discard = function() {
	if (YAHOO.util.Dom.get("discard_radio").checked) {
		return CPANEL.validate.min_length(YAHOO.util.Dom.get("failmsgs").value, 1);
	}
	else return true;
};

var validate_dirpath = function() {
	if (YAHOO.util.Dom.get("pipeit").checked) {
		return CPANEL.validate.dir_path(YAHOO.util.Dom.get("pipefwd").value);
	}
	else return true;	
};

var forward_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('Forward Address')">");
var fwd_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('Destination Address')">");
var discard_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('Discard Message')">");
var dir_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('Directory')">");
var system_user_validator = new CPANEL.validate.validator("<cpanel Locale="maketext('System Account')">");

function init_page() {

    system_user_validator.add("fwdsystem", validate_system_user, "<cpanel langprint="username_invalid">", "fwdsystem_radio");
    system_user_validator.attach();
	
	forward_validator.add("email", "local_part_email(%input%, 'cpanel')", "<cpanel langprint="email_not_valid_email">");
	forward_validator.attach();
	
	fwd_validator.add("fwdemail", validate_destination, "<cpanel langprint="email_not_valid_email">");
	fwd_validator.attach();
	
	discard_validator.add("failmsgs", validate_discard, "<cpanel langprint="email_fwd_discard_not_empty">");
	discard_validator.attach();
	
	dir_validator.add("pipefwd", validate_dirpath, "<cpanel langprint="validation_directory_paths">");
	dir_validator.attach();
	
	CPANEL.validate.attach_to_form("submit", [
        forward_validator,
        fwd_validator,
        discard_validator,
        dir_validator,
        system_user_validator
    ]);
	
	YAHOO.util.Dom.get("email").focus();
	YAHOO.util.Event.on("toggle_advanced_options", "click", function() { CPANEL.animate.slide_toggle("advance") });
	YAHOO.util.Event.on(["fwd_radio", "discard_radio", "pipeit", "fwdopt_blackhole"], "click", toggle_radios);
	
	// select the radio button when an input field gets focus
	YAHOO.util.Event.on("fwdemail", "focus", function() { YAHOO.util.Dom.get("fwd_radio").checked = true; toggle_radios(); });
	YAHOO.util.Event.on("failmsgs", "focus", function() { YAHOO.util.Dom.get("discard_radio").checked = true; toggle_radios(); });
	YAHOO.util.Event.on("pipefwd", "focus", function() { YAHOO.util.Dom.get("pipeit").checked = true; toggle_radios(); });
    YAHOO.util.Event.on("fwdsystem", "focus", function() { YAHOO.util.Dom.get("fwdsystem_radio").checked = true; toggle_radios(); });
}
YAHOO.util.Event.onDOMReady(init_page);
</cpanelif>
//]]>
</script>
<div class="body-content">
<cpanelfeature cgpro_forwardersemail>	

<h1><cpanel langprint="FWAddanew"></h1>
<br />
<div class="highlight">
<form method="post" name="fwdf" id="fwdf" action="doaddfwd.html">

    <h2><cpanel langprint="EMAILAddress"></h2>
    <table cellspacing="4">
	    <cpanelif $appname==webmail>
			<tr>
				<td><cpanel langprint="FWForwarding"></td>
				<td><input id="email" type="hidden" name="email" value="<cpanel print="$authuser">" /><cpanel print="$authuser"></td>
			</tr>
	    </cpanelif>
	    <cpanelif !$appname==webmail>
			<tr>
				<td><cpanel langprint="FWForwardAddress"> <input id="email" type="text" name="email" size="25" />@<select name="domain"><cpanel Email="printdomainoptions()"></select></td>
				<td><span id="email_error"></span></td>
			</tr>
	    </cpanelif>
    </table>
    <br />
    
    <h2><cpanel langprint="FWDestination"></h2>
    <div class="formbox">
	
	<cpanelif $appname==webmail>
		<input name="fwdopt" id="fwd_radio" type="hidden" value="fwd" />
		<table><tr>
		<td><p><cpanel langprint="FWForwardTo">: <input name="fwdemail" id="fwdemail" type="text" size="40" /> </p></td>
		<td><span id="fwdemail_error"></span></td>
		</tr></table>
	</cpanelif>
    
	<cpanelif !$appname==webmail>
		<input name="fwdopt" id="fwd_radio" type="hidden" value="fwd" checked="checked" /> <label for="fwd_radio"><cpanel langprint="FWForwardTo"></label>: <input name="fwdemail" id="fwdemail"  type="text" size="40" /> <span id="fwdemail_error"></span>
		<br /><br />

		
		<input name="fwdopt" type="hidden" value="fail" id="discard_radio" /> <label for="discard_radio"></label><br />
		<blockquote>
			<input name="failmsgs" id="failmsgs" type="hidden" size="40"  value="<cpanel langprint="FWNoSuchPerson">" /> <span id="failmsgs_error"></span>
		</blockquote>

	    <div style="display: none;" id="advance">

            <label><input id="fwdsystem_radio" name="fwdopt" type="radio" value="system" id="system_radio" /> <cpanel Locale=maketext("Forward to a system account")></label>: <input id="fwdsystem" name="fwdsystem" type="text" size="20" value="<cpanel print="$CPDATA{'USER'}">" />
            <span id="fwdsystem_error" style="vertical-align: middle"></span>
            <br /><br />
			<input name="fwdopt" id="pipeit" type="radio" value="pipe" /> <label for="pipeit"><cpanel langprint="FWPipe"></label><br />
			<blockquote>
				<cpanel setvar="autoinput=pipefwd">
				<table border="0" cellspacing="0" cellpadding="0">
					<tr><td><img src="../images/homeb.gif" alt="home" align="middle" />/</td><td><cpanel relinclude="autodir/dirbox.html"></td></tr>
				</table>
				<br />
				<cpanel langprint="FWPipeHint1">
			</blockquote>
		
			<input name="fwdopt" type="radio" value="blackhole" id="fwdopt_blackhole" /> <label for="fwdopt_blackhole"><cpanel langprint="FWDiscard"></label>
			<br />
			<br />
	    </div>
    </cpanelif>
	
    </div><!-- end formbox -->
    
	<br />
    <input class="input-button" type="submit" id="submit" value="<cpanel langprint="FWAddHead">" />
</form>
</div>

<div class="return-link"><a href="fwds.html">&larr; <cptext "Go Back"></a></div>

</cpanelfeature>
</div><!-- end body-content -->

<cpanel Branding="include(stdfooter.html)">
